package com.test.webmanage.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.test.webmanage.mapper.EmpMapper;
import com.test.webmanage.pojo.Emp;
import com.test.webmanage.pojo.PageBean;
import com.test.webmanage.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;
    public PageBean list(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
//        return new PageBean(empMapper.count(),empMapper.page((page-1)*pageSize,pageSize));
        PageHelper.startPage(page,pageSize);
        List<Emp> emps= empMapper.list(name, gender, begin, end);
        Page<Emp> p=(Page<Emp>) emps;
        return new PageBean(p.getTotal(),p.getResult());

    }
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }
    public void add(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.add(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }
    public Emp login(Emp emp) {
        return empMapper.login(emp);
    }
}
